﻿//$LastChangedDate: 2012-02-16 15:49:15 +0100 (do, 16 feb 2012) $
//$LastChangedRevision: 7 $
//$LastChangedBy: jan-willem $

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TLD_Vision
{
    public class Histogram
    {
        private int[] data;

        public int this[int i]
        {
            get { return this.data[i]; }
            set { this.data[i] = value; }
        }

        public int Length {
            get { return this.data.Length; }
        }

        public Histogram(int binSize)
        {
            data = new int[binSize];
        }

        public double[] Normalize()
        {
            int sum = data.Sum();

            double[] normHist = new double[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                normHist[i] = (double)data[i] / sum;
            }

            return normHist;
        }

        public Histogram Cumulative()
        {
            Histogram cumulative = new Histogram(data.Length);
            int sum = 0;

            for (int i = 0; i < data.Length; i++)
            {
                sum += data[i];
                cumulative[i] = sum;
            }

            return cumulative;
        }

        public int Sum()
        {
            return data.Sum();
        }
    }
}
